package com.example.controller;

import com.example.common.PageResult;
import com.example.common.Result;
import com.example.dto.VisitRecordWithStuDto;
import com.example.dto.VisitRecordWithStuPageDto;
import com.example.entity.VisitUser;
import com.example.service.VisitUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping("/admin/visit")
@RestController
@CrossOrigin
public class VisitUserController {

    @Autowired
    private VisitUserService visitUserService;
    @GetMapping("/page")

    public Result<PageResult> page(VisitRecordWithStuPageDto vpDto){
        PageResult page =  visitUserService.page(vpDto);
        return Result.success(page);
    }

    @PostMapping("/add")
    public Result add(@RequestBody VisitRecordWithStuDto VisDto){
        visitUserService.add(VisDto);
        return Result.success();
    }

    @DeleteMapping("{dno}/{sno}")
    public Result deleteBySnoWithDno(@PathVariable String dno,@PathVariable String sno){
        log.info("接收到参数{}{}",dno,sno);
        visitUserService.deleteBySnoWithDno(dno,sno);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody VisitRecordWithStuDto visDto){
        log.info("接收到访问宿舍请求参数{}",visDto);
        visitUserService.update(visDto);
        return Result.success();
    }
}
